home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / jade / lisp / server.jl < prev    next >
Lisp/Scheme  |  1995-03-09  |  3KB  |  74 lines

  1. ;;;; server.jl -- Lisp code for the edit server
  2. ;;;  Copyright (C) 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. ;;; This file is part of Jade.
  5.  
  6. ;;; Jade is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;; any later version.
  10.  
  11. ;;; Jade is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;;; GNU General Public License for more details.
  15.  
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Jade; see the file COPYING.  If not, write to
  18. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. (provide 'server)
  21.  
  22. (defvar server-open-window nil
  23.   "Determines which window a client file gets displayed in. There are three
  24. possible values,
  25.   nil    - Use the current window
  26.   other - Use the `other' window
  27.   t    - Open a new window")
  28.  
  29. ;;;###autoload
  30. (defun server-open-file (file line-number)
  31.   "This function is called by the editor's main event loop when a client
  32. process asks us to edit a file -- its job is to load the specified file
  33. into a new buffer and display it at line LINE-NUMBER."
  34.   (let
  35.       (buf win)
  36.     (unless (setq buf (get-file-buffer file))
  37.       (unless (setq buf (open-file file))
  38.     (server-reply file 10)
  39.     (return)))
  40.     (setq win
  41.       (cond
  42.        ((eq server-open-window 'other)
  43.     (other-window))
  44.        ((null server-open-window)
  45.     (current-window))
  46.        (t
  47.     (open-window))))
  48.     (with-window win
  49.       (goto-buffer buf)
  50.       (goto-char (pos 0 line-number))
  51.       (message (format nil "Client file `%s'." file)))
  52.     (with-buffer buf
  53.       (add-hook 'kill-buffer-hook 'server-file-kill))
  54.     buf))
  55.  
  56. ;; Hooked into kill-buffer, replies to the client if necessary
  57. (defun server-file-kill (buf)
  58.   (when (server-reply buf)
  59.     (message (format nil "Client file `%s' finished."
  60.              (buffer-file-name buf))))
  61.   t)
  62.  
  63. ;;;###autoload
  64. (defun server-close-file ()
  65.   "Tell the client program which asked us to edit the file in the current
  66. buffer that we've finished with it. *The file will NOT be saved* automatically
  67. -- you're supposed to do that before calling this function if you want to."
  68.   (interactive)
  69.   (if (server-reply)
  70.       (progn
  71.     (remove-hook 'kill-buffer-hook 'server-file-kill)
  72.     (format t "Client file `%s' replied to." (buffer-file-name)))
  73.     (error "This buffer has no client!")))
  74.